var myScroll;
$(function (){
	

	
init()
function init(){
	var hh=$(window).height();
	
	$("#container").css({"height":(hh-400)});
	$(".floatpage").css({"height":(hh-400)});
	$(".box360").css({"height":(hh-190)});
	$("#container360").css({"height":(hh-190)});
	}	

//myScroll.refresh();

/******/	
//*********************************************
var imgarr=[
		"images/page2.png",
		"images/car.png",
		"images/car2.png",
		"images/1_o_0.jpg",
		"images/1_o_1.jpg",
		"images/1_o_2.jpg",
		"images/1_o_3.jpg",
		"images/1_o_4.jpg",
		"images/1_o_5.jpg",
		"images/1_o_preview_0.jpg",
		"images/1_o_preview_1.jpg",
		"images/1_o_preview_2.jpg",
		"images/1_o_preview_3.jpg",
		"images/1_o_preview_4.jpg",
		"images/1_o_preview_5.jpg",
		"images/page1.png"
		];
	
var imglen=0;
var tImgLen=0;
var loadingArr=[];
var loadingtimer=null;
var timers;
var loadingimglen=imgarr.length;

var loadImages=[];



loadingImg();
LoadAnim();
function loadingImg(){
	for(var i=0;i<loadingimglen;i++){
		loadImages[i]=new Image();
		loadImages[i].src=imgarr[i];
		loadImages[i].onload = imageOnloadHandler;
		}
	}

function imageOnloadHandler(){
	imglen++;
	
	var loadinglen=imglen/loadingimglen; 
	
	if(imglen>=loadingimglen){
		loadingArr.push(360);
		
		}else{
			var angle=loadinglen*360;
			loadingArr.push(angle);
			
			}

}

function LoadAnim(){
	timers=setInterval(function (){
		tImgLen++;
		
		if(loadingArr[tImgLen]>180){
				
				
				//setCss3($(".cricleLeft")[0],{"transform":"rotate(180deg)"})
				//setCss3($(".cricleRight")[0],{"display":"block","transform":"rotate("+(loadingArr[tImgLen]-180)+"deg)"});
				//$(".circleShade").css({display:"none"});
				}else{
				
				//setCss3($(".cricleLeft")[0],{"transform":"rotate("+loadingArr[tImgLen]+"deg)"});	
					}
		$(".loadingnum").html(parseInt((loadingArr[tImgLen]/360)*100)+"%");	
				
		if(tImgLen==loadingArr.length){
			clearInterval(timers);
			$(".loadingnum").html("100%");	
			$(".outbox").css({display:"block",opacity:1});
			//setTimeout(function (){	
				$(".box").css({display:"block"});
				$(".loadingOutbox").animate({opacity:0},500,function (){
					$(".loadingOutbox").css({display:"none"});
					
					 
					carAnimate();
					
					
					
					
					})
			/// },300)
			
			
			
			}
		
		
		},150)
	
	}
	
	
/******/	
function carAnimate(){
	var myScroll = new iScroll('outbox', {
						click:true,
						mouseWheel: true,
						scrollbars: true,
						interactiveScrollbars: false,
						shrinkScrollbars: 'scale',
						fadeScrollbars: true
					});	
				
	myScroll.disable();			
	TweenMax.to(".car",0.8,{x:940,onComplete:scaleCar});				
	function scaleCar(){
		$(".car2").addClass("car2Anim");
		setTimeout(function (){
			
			overallView();
			//
			},300)
		}
	var contuneBtn=document.getElementById("arrow01");
	contuneBtn.addEventListener("touchstart" , function (){
		myScroll.enable();
		myScroll.refresh();
		},false);
	contuneBtn.addEventListener("touchend" , function (){
			myScroll.scrollTo(0,$(window).height(),1000,true) ;
		},false);
					
	
	}	


/*$(".arrow01").click(function (){
	alert(123)
	})*/



function setCss3 (obj,attrObj) {
   for (var i in attrObj) {
     var newi=i;
	 if(newi.indexOf("-")>0){
	   var num=newi.indexOf("-");
	   newi=newi.replace(newi.substr(num,2),newi.substr(num+1,1).toUpperCase());
	 }
	 obj.style[newi]=attrObj[i];
	 newi=newi.replace(newi.charAt(0),newi.charAt(0).toUpperCase());
	 obj.style["webkit"+newi]=attrObj[i];
	 obj.style["moz"+newi]=attrObj[i];
	 obj.style["o"+newi]=attrObj[i];
	 obj.style["ms"+newi]=attrObj[i];
   }
  }	
	})